﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace HRDexCapstoneProject.Functions.Employees
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\HRdexDB.mdf;Integrated Security=True;User Instance=True");

        protected void Page_Load(object sender, EventArgs e)
        {
            //Panel1.Visible = true;
            //pOutput.Visible = false;
        }

        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            conn.Open();

            SqlCommand cmd = new SqlCommand("Insert Into  formEmployees (EmployeeID, LastName, FirstName, MiddleName, catPositionsID, CollegeID, DeptID, UserLevelID, Password, Address, Birthday, Email, ContactNo)"+
                "Values (@empNo, @lname, @fname, @mname, @position, @college, @dept, @ulevel, @pass, @address, @birthday, @email, @contactno)", conn);
            Stream fs = fuPicture.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);


            cmd.Parameters.Add("@empNo", SqlDbType.Int).Value = txtEmpNum.Text;
            cmd.Parameters.Add("@lname", SqlDbType.VarChar).Value = txtLName.Text;
            cmd.Parameters.Add("@fname", SqlDbType.VarChar).Value = txtFName.Text;
            cmd.Parameters.Add("@mname", SqlDbType.VarChar).Value = txtMName.Text;
            cmd.Parameters.Add("@position", SqlDbType.Int).Value = ddlPosition.Text;
            cmd.Parameters.Add("@college", SqlDbType.Int).Value = ddlCollege.Text;
            cmd.Parameters.Add("@dept", SqlDbType.Int).Value = ddlPosition.Text;
            cmd.Parameters.Add("@ulevel", SqlDbType.Int).Value = ddlUserLevel.Text;
            cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = txtPassword.Text;
            cmd.Parameters.Add("@address", SqlDbType.VarChar).Value = txtAddress.Text;
            cmd.Parameters.Add("@birthday", SqlDbType.VarChar).Value = ddl0Month.Text + "/" + ddl0Day.Text + "/" + ddl0Year.Text;
            cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtEmail.Text;
            cmd.Parameters.Add("@contactno", SqlDbType.VarChar).Value = txtContactNo.Text;
            //cmd.Parameters.Add("@pic", SqlDbType.Image).Value = bytes;

            
            cmd.ExecuteNonQuery();

            conn.Close();
        }

        protected void btnEdit_Click(object sender, ImageClickEventArgs e)
        {

        }


   
    }
}